package ShareYourWay.functions;

import org.apache.wicket.Session;
import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.request.Request;

import ShareYourWay.project.User;
import ShareYourWay.webpages.HomePage;



public class SignInSession extends AuthenticatedWebSession {
	
	private User user  = new User(); // usuario autenticado
	private User u; // usuario (sólo mail y pass) para autenticarlo
	
	
	private App app = new App();
	
	
	public SignInSession(Request request) {
		super(request);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean authenticate(String mail, String password) {
		// TODO Auto-generated method stub
		
		System.out.println("authenticate!!!!");
		
		user.setMail(mail);
		user.setPassword(password);
		 		
		u=app.Login(user);
		
				
		if(u!=null) {			
			
			
			this.setUser(u);
			System.out.println("--------------!!!!!!!!!!!"+u.getName());
			return true;
			
		}
			
		else
			return false;	
		
		//return mail.equals("admin") && password.equals("admin");
        
	}
	
	public static SignInSession get() {
		return (SignInSession)Session.get();
	}

	

	@Override
	public Roles getRoles() {
		// TODO Auto-generated method stub
		
	     if (isSignedIn()) {
	           return new Roles(Roles.USER);
	       }
	    
	     
	       return new Roles();
		
	}
	
	/**
     * @return User
     */
    public User getUser()
    {
        return user;
    }

    /**
     * @param user
     *            New user
     */
    public void setUser(final User u)
    {
        this.user = u;
    }

	
	

}
